package com.library.service.impl;

import com.library.dao.UserDao;
import com.library.model.User;
import com.library.security.TokenProvider;
import com.library.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    private final UserDao userDao;
    private final TokenProvider tokenProvider;

    public UserServiceImpl(UserDao userDao, TokenProvider tokenProvider) {
        this.userDao = userDao;
        this.tokenProvider = tokenProvider;
    }

    @Override
    public User findByUsername(String username) {
        return userDao.findByUsername(username);
    }

    @Override
    public boolean save(User user) {
        return userDao.save(user) > 0;
    }

    @Override
    public String getUsernameFromToken(String token) {
        return tokenProvider.getUsernameFromJWT(token);
    }
}
